package com.spring.commonality.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.spring.commonality.po.CharsBean;
import com.spring.commonality.po.CommonFeedBack;
import com.spring.commonality.service.ICommonFeedBackService;
import com.spring.commonality.service.IGeneralCharsService;
import com.spring.trade.dto.TradeOrderInfoDto;
import com.spring.trade.po.TradeOrderInfo;
import com.spring.trade.service.ITradeOrderInfoService;

@Service
public class GeneralCharsServiceImpl implements IGeneralCharsService {

	@Autowired
	private ICommonFeedBackService commonFeedBackService;
	@Autowired
	private ITradeOrderInfoService tradeOrderInfoService ;

	@Override
	public Map<String, Object> getFeedBackPieChartData() {
		Map<String, Object> map = new HashMap<String, Object>();
		// 回馈状态 0,未处理 1,已处理
		CommonFeedBack cfb = new CommonFeedBack();
		cfb.setStatus(0);
		List<CommonFeedBack> noAuthList = commonFeedBackService.findFeedBackList(cfb);
		cfb.setStatus(1);
		List<CommonFeedBack> authList = commonFeedBackService.findFeedBackList(cfb);
		List<CharsBean> list = new ArrayList<>();
		list.add(new CharsBean("未处理", noAuthList.size()));
		list.add(new CharsBean("已处理", authList.size()));
		map.put("series", list);
		return map;
	}

	@Override
	public Map<String, Object> getOrderFormChartDate(String type) {
		List<TradeOrderInfoDto> list=null;
		if (type.equals("day")) {
			list = tradeOrderInfoService.getOrderFormChartList();
		}else if (type.equals("Month")) {
			list = tradeOrderInfoService.findOrderFormChartMonthsList();
		}
		List<String> createTime=new ArrayList<>();
		List<String> orderNum=new ArrayList<>();
		if(!CollectionUtils.isEmpty(list)){
			for (TradeOrderInfoDto info : list) {
				createTime.add(info.getCreateTimeStr());
				orderNum.add(info.getOrderNum());
			}
		}
		Map<String, Object> map= new HashMap<>();
		map.put("createTime", createTime);
		map.put("orderNum", orderNum);	
		return map;
	}

	@Override
	public Map<String, Object> findOrderFormChartWeeksData() {
		List<TradeOrderInfo> list = tradeOrderInfoService.findOrderFormChartWeeksData();
		List<String> timeList = new ArrayList<>();
		List<Integer> orderNum = new ArrayList<>();
		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if(!CollectionUtils.isEmpty(list)){
			for (TradeOrderInfo info : list) {
				String createTime = sdf.format(info.getCreateTime()).substring(0, 10);
				String endTime = sdf.format(info.getEndTime()).substring(0, 10);
				StringBuffer sb = new StringBuffer();
				sb.append(createTime).append("到").append(endTime);
				timeList.add(sb.toString());
				orderNum.add(info.getRecordNum());
			}
		}
		Map<String, Object> map= new HashMap<>();
		map.put("createTime", timeList);
		map.put("orderNum", orderNum);	
		return map;
	}
}
